package org.example.chat.api;

import lombok.Data;

/**
 * 统一响应结果
 * @author cheval
 */
@Data
public class CommonResult<T> {

    private Long code;
    private String message;
    private T data;

    private CommonResult(Long code, String message) {
        this.code = code;
        this.message = message;
    }
    private CommonResult(Long code, String message,T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    public static CommonResult success() {
        return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }

    public static CommonResult success(String message) {
        return new CommonResult(ResultCode.SUCCESS.getCode(), message);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),data);
    }

    public static <T> CommonResult<T> success(String message, T data) {
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
    }

    public static CommonResult successNoMessage() {
        return new CommonResult(ResultCode.SUCCESS.getCode(), null);
    }

    public static <T> CommonResult<T> successNoMessage(T data) {
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), null, data);
    }

    public static CommonResult fail() {
        return new CommonResult(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMessage());
    }

    public static CommonResult fail(String message) {
        return new CommonResult(ResultCode.FAIL.getCode(), message);
    }

    public static CommonResult failNoMessage() {
        return new CommonResult(ResultCode.FAIL.getCode(), null);
    }

    public static CommonResult unAuthenticated() {
        return new CommonResult(ResultCode.UNAUTHENTICATED.getCode(), ResultCode.UNAUTHENTICATED.getMessage());
    }

    public static CommonResult forbidden() {
        return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage());
    }

    public static <T> CommonResult<T> validateFail(T data) {
        return new CommonResult(ResultCode.VALIDATE_FAIL.getCode(), ResultCode.VALIDATE_FAIL.getMessage(),data);
    }
}
